package com.dejavu.c4.controller;


import com.dejavu.c4.pojo.User;
import com.dejavu.c4.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @GetMapping("/findUserById/{id}")
    public User findUserById(@PathVariable("id")int id){
        User userById = userService.findUserById(id);
        return userById;

    }

    @GetMapping("/userList")
    public String userList(@RequestParam(name="page",required = true,defaultValue = "1")int page
            , @RequestParam(name="size",required = true,defaultValue = "10")int size, Model model, User user){
        List<User> userByMany = userService.findUserByMany(page, size, user);
        PageInfo pageInfo = new PageInfo(userByMany);
        model.addAttribute("pageInfo",pageInfo);
        return "table";
    }

    @GetMapping("/toTable")
    public String toTable(){
        return "table";
    }

    @GetMapping("/toIndex")
    public String toIndex(){
        return "index";
    }

    @GetMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

}
